﻿/*
*
*   var combinedGroups = $.getCombineArray([1, 2, 3, 4], ['a', 'b', 'c', 'd'], ['x', 'y', 'z']);
*
*   for (var i in combinedGroups) {
*       var items = combinedGroups[i];
*       for (var j in items) {
*           document.write(items[j]);
*       }
*       document.writeln("<br/>");
*    }
*
*    result:
*          1ax
*          1ay
*          1az
*          1bx
*          1by
*
*          ...
*
*
*
*
*/

$.matrix = function () {

    var _groups = arguments;

    var _result = new Array();

    var _tempArray = new Array();

    function createSubTree(index) {
        for (var i in _groups[index]) {
            _tempArray[index] = _groups[index][i];

            // it is last group
            if (index == _groups.length - 1) {
                _result.push(_tempArray.concat());
            }
            else {
                createSubTree(index + 1);
            }
        }
    }

    // get combine array
    createSubTree(0);

    return _result;
};